package com.example.spring.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.spring.demo.common.model.req.GoodsOrderParam;
import com.example.spring.demo.common.model.vo.GoodsOrderVo;
import com.example.spring.demo.entity.GoodsOrder;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/31 10:47
 **/
public interface GoodsOrderMapper extends BaseMapper<GoodsOrder> {
    //查询订单列表
    @Select("""
<script>
select
go.order_id,g.goods_name,g.goods_price,g.image,u.nick_name,go.price,go.create_time from goods_order as go
inner join goods as g on g.goods_id = go.goods_id
inner join wx_user as u on u.user_id = go.order_user
where 1=1
<if test="goodsName != null and goodsName != ''">
and g.goods_name like concat('%',#{goodsName},'%')
</if>
order by go.create_time desc limit #{curPage},#{pageSize}
</script>
""")
    List<GoodsOrderVo> getList(GoodsOrderParam param);
    //查询订单总数
    @Select("""
<script>
select count(*) from goods_order as go
inner join goods as g on g.goods_id = go.goods_id
inner join wx_user as u on u.user_id = go.order_user
where 1=1
<if test="goodsName != null and goodsName != ''">
and g.goods_name like concat('%',#{goodsName},'%')
</if>
</script>
""")
    Long findTotalCount(GoodsOrderParam param);
}
